package service

import (
	"trpg-base/entity"
	"trpg-common/constants"
	"trpg-common/utils/gorm_util"
	"trpg-common/utils/time_util"
)

type SystemMessageService struct{}

func (SystemMessageService) SendMessage(message string, uid string) {
	systemMessage := entity.SystemMessage{}
	systemMessage.Message = message
	systemMessage.Uid = uid
	systemMessage.Creator = uid
	systemMessage.Modifier = uid
	systemMessage.GmtCreated = time_util.Now()
	systemMessage.GmtModified = time_util.Now()
	gorm_util.InsertUpdateOne(&systemMessage)
}

func (SystemMessageService) CountMessage(uid string) int64 {
	return systemMessageDao.CountMessage(uid)
}

func (SystemMessageService) GetMessages(uid string) []entity.SystemMessage {
	res := make([]entity.SystemMessage, 0)
	gorm_util.SelectByParamBuilder(gorm_util.NewParamBuilder().Model(&entity.SystemMessage{}).Eq("uid", uid).Eq("is_deleted", constants.DeleteNo).OrderByDesc("gmt_created"), &res)
	return res
}
